//
//  HYTopThemeView.m
//  _normal
//
//  Created by Ezra on 16/6/6.
//  Copyright © 2016年 Ezra. All rights reserved.
//

#import "HYTopThemeView.h"
#import "HYThemeItem.h"
#import <SDWebImage/UIImageView+WebCache.h>

#import "NSDate+Timer.h"

@interface HYTopThemeView()

@property (weak, nonatomic) IBOutlet UIImageView *iconImgView;

@property (weak, nonatomic) IBOutlet UILabel *nameLab;

@property (weak, nonatomic) IBOutlet UILabel *subText;



@end

@implementation HYTopThemeView

+ (instancetype)viewForXib
{
    return [[[NSBundle mainBundle]loadNibNamed:@"HYTopThemeView" owner:nil options:nil]firstObject];
}


-(void)setItem:(HYThemeItem *)item
{
    [super setItem:item];
    
    self.nameLab.text = item.title;
//  self.timeLab.text = item.created_at;
    self.iconImgView.layer.masksToBounds = YES;
    
    self.iconImgView.layer.cornerRadius = self.iconImgView.HY_width/2 ;
    
    [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:item.userAvatar]];
    
    
    // 在设置时间的时候,就处理
    // 发帖 :   2016-06-08 09:07:45 创建帖子时间
    // 获取发帖日期对象
    // 创建日期格式字符串(把日期对象转换成字符串,字符串转换日期对象)
    // 把发帖日期字符串转换日期对象
    NSDateFormatter *fmt = [[NSDateFormatter alloc]init];
    fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
//    NSDate *passDate = [fmt dateFromString:item.created_at];
    
    // 获取当前发帖日期与当前时间日期 差值
//    NSDateComponents *cmp = [passDate differenceWithNow];
    
//    NSString *timerStr = item.created_at;
    
//    if ([passDate isThisYear]) {
//
//        if ([passDate isThisToday]) {
//
//            if (cmp.hour >= 1) {
//                timerStr = [NSString stringWithFormat:@"%ld小时前",cmp.hour];
//            }else if (cmp.minute >= 1 ){
//                timerStr = [NSString stringWithFormat:@"%ld分钟前",cmp.minute];
//            }else{
//                timerStr = @"刚刚";
//            }
//        }else if ([passDate isThisYesterday]){
//
//            fmt.dateFormat = @"昨天 HH:mm";
//
//            timerStr = [fmt stringFromDate:passDate];
//
//        }else{
//            fmt.dateFormat = @"MM-dd HH:mm";
//
//            timerStr = [fmt stringFromDate:passDate];
//        }
//
//    }
    self.subText.text = item.subhead;
}


@end
